"""
os.walk(目录路径)：递归显示文件目录下的所有文件及其路径（目录包含子目录）
os.rename(oldname,newname):重命名
"""

import os
import datetime

# result = os.walk(r"E:\python\utils\北京")
#for i in result:
#    print(i)

def getfilepath(directory):
    filepath_list = []
    for direct, direct_name,filename in os.walk(directory):
        if len(filename) != 0:
            for i in filename:
                filepath = direct +"\\" +i
                filepath_list.append(filepath)
    return filepath_list

def rename_file(directory):
    day = datetime.datetime.now().strftime("%Y_%m_%d")
    for file_path in getfilepath(directory):
        old_file_path = file_path.split(".")[0]
        suffx = file_path.split(".")[1]
        new_file = old_file_path + "_" +day+"."+suffx
        os.rename(file_path,new_file)

if __name__ == '__main__':
    aa = getfilepath(r"E:\python\utils\北京")
    # print(aa)
    for i in aa:
        print(i)
    # rename_file(r"E:\python\utils\北京")